import 'dart:ui' as ui;

import 'package:flutter/widgets.dart';

class AppDesign {
  /// 屏幕物理宽度
  static late double physicalWidth;

  /// 屏幕物理高度
  static late double physicalHeight;

  /// 屏幕逻辑宽度
  static late double screenWidth;

  /// 屏幕逻辑高度
  static late double screenHeight;

  /// 状态栏高度，刘海屏会更高
  static late double statusBarHeight;

  /// 底部安全区距离，适用于全面屏下面有按键的
  static late double bottomBarHeight;

  /// 设备像素比
  static late double pixelRatio;

  /// 缩放比例
  static late double scaleRatio;

  /// 初始化
  static void init(BuildContext context, {double designWidth = 375}) {
    physicalWidth = ui.window.physicalSize.width;
    physicalHeight = ui.window.physicalSize.height;
    pixelRatio = ui.window.devicePixelRatio;

    final query = MediaQuery.of(context);
    screenWidth = query.size.width;
    screenHeight = query.size.height;
    statusBarHeight = query.padding.top;
    bottomBarHeight = query.padding.bottom;
    scaleRatio = screenWidth / designWidth;
  }

  static double setWidth(double size) => size * scaleRatio;

  static void debug() {
    debugPrint("""==========
屏幕尺寸: $screenWidth * $screenHeight
物理像素: $physicalWidth * $physicalHeight
像素比: $pixelRatio
缩放比：$scaleRatio
状态栏高度: $statusBarHeight
底部安全区高度: $bottomBarHeight
==========""");
  }
}

extension Rpx on num {
  double get rpx => AppDesign.setWidth(toDouble());
}
